using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class AddContactsPage : BasePage
	{
		private const string TAG = "AddContactsPage";
		private const int cNPageArgCnt = 1;
		private MMStandardUIEvent mDlgGetContacts;
		private string mStrTitle;
		private ContactsViewType mContactsViewType;
		private List<string> mListFilterUser;
		public static AddContactsPageArgs sAddContactsPageArgs;
		private EventWatcher mWatchxxx;
		private object mObjectWatcher = new object();
		private ApplicationBar mBar;
		internal Grid LayoutRoot;
		internal panelTitle2Line panelTitle;
		internal Grid ContentPanel;
		internal ContactsView mContactView;
		private bool _contentLoaded;
		public AddContactsPage()
		{
			this.InitializeComponent();
			base.set_ApplicationBar(this.GetApplicationBar());
			ContactsView.resetCheckedList();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("AddContactsPage", "Page_Loaded");
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("AddContactsPage", "Page_Unloaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("AddContactsPage", "OnPageIn");
			if (object_0 != null && 1 == object_0.Length && object_0[0] is AddContactsPageArgs)
			{
				AddContactsPageArgs addContactsPageArgs = object_0[0] as AddContactsPageArgs;
				if (addContactsPageArgs != null)
				{
					this.mDlgGetContacts = addContactsPageArgs.mDlgGetContacts;
					this.mContactsViewType = addContactsPageArgs.mType;
					this.mListFilterUser = addContactsPageArgs.mListFilter;
					this.mStrTitle = addContactsPageArgs.mStrTitle;
					this.mContactView.mNFilterContactsType = addContactsPageArgs.mNFilterKind;
				}
				AddContactsPage.sAddContactsPageArgs = addContactsPageArgs;
				this.initUI();
				return;
			}
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("AddContactsPage", "OnPageOut");
			AddContactsPage.sAddContactsPageArgs = null;
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("AddContactsPage", "OnPageBack");
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void ConListHeaderImportFromGroup_ItemClick(object sender, object object_0)
		{
			ImportFromGroupPage.GotoThisPage(new MMStandardUIEvent(this.selectGroupCallBack));
		}
		private void initUI()
		{
			this.mContactView.mContactViewType = this.mContactsViewType;
			ContactsView.resetCheckedList(this.mListFilterUser);
			if (!string.IsNullOrEmpty(this.mStrTitle))
			{
				this.panelTitle.strSecondTitle = this.mStrTitle;
			}
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
		}
		private ApplicationBar GetApplicationBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			if (this.mBar != null)
			{
				this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
				this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
			}
			ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton(new Uri("/icons/appbar.check.rest.png", 2));
			applicationBarIconButton.set_Text(strings.COM_Confirm);
			applicationBarIconButton.add_Click(new EventHandler(this.btnOk_Click));
			applicationBarIconButton.set_IsEnabled(false);
			this.mBar.get_Buttons().Add(applicationBarIconButton);
			this.setAppBarStyle(this.mBar);
			return this.mBar;
		}
		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.mDlgGetContacts == null)
			{
				base.GoBack();
				return;
			}
			List<Contact> checkedItem = ContactsView.getCheckedItem();
			AddContactsPageCBArg addContactsPageCBArg = new AddContactsPageCBArg();
			this.mDlgGetContacts(addContactsPageCBArg, checkedItem);
			if (addContactsPageCBArg.mStrPagePath != null)
			{
				ToolFunction.GotoPageForUserControl(addContactsPageCBArg.mStrPagePath, addContactsPageCBArg.mPageArgs, true);
				return;
			}
			base.GoBack();
		}
		public void ItemCheckChanged(object sender, object object_0)
		{
			List<Contact> checkedItem = ContactsView.getCheckedItem();
			ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton();
			if (base.get_ApplicationBar() == null || base.get_ApplicationBar().get_Buttons().get_Count() == 0)
			{
				return;
			}
			applicationBarIconButton = (ApplicationBarIconButton)base.get_ApplicationBar().get_Buttons().get_Item(0);
			if (checkedItem.get_Count() == 0)
			{
				applicationBarIconButton.set_IsEnabled(false);
				return;
			}
			applicationBarIconButton.set_IsEnabled(true);
		}
		private void selectGroupCallBack(object sender, object object_0)
		{
			if (object_0 == null)
			{
				return;
			}
			Contact contact = object_0 as Contact;
			if (contact == null)
			{
				return;
			}
			AddContactsPageCBArg addContactsPageCBArg = new AddContactsPageCBArg();
			addContactsPageCBArg.mConIfItsGroup = contact;
			List<Contact> friendContatsFromChatRoomName = ChatRoomMgr.getFriendContatsFromChatRoomName(contact.strUsrName);
			this.mDlgGetContacts(addContactsPageCBArg, friendContatsFromChatRoomName);
			if (addContactsPageCBArg.mStrPagePath != null)
			{
				PageManager.getInstance().PopPage();
				ToolFunction.GotoPageForUserControl(addContactsPageCBArg.mStrPagePath, addContactsPageCBArg.mPageArgs, true);
				return;
			}
			PageManager.getInstance().PopPage();
		}
		public static void GotoThisPage(AddContactsPageArgs pageArgs)
		{
			object[] object_ = new object[]
			{
				pageArgs
			};
			ToolFunction.GotoPageForUserControl("/Source/UI/Contact/AddContactsPage.xaml", object_, false);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/AddContactsPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.mContactView = (ContactsView)base.FindName("mContactView");
		}
	}
}
